package com.zupig.videoguide;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

public class WelcomeActivity extends AppCompatActivity implements View.OnClickListener {

    protected CustomVideoView cvv;
    protected Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.setContentView(R.layout.activity_welcome);
        initView();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn) {
            startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
            finish();
        }
    }

    private void initView()  {
        cvv = (CustomVideoView) findViewById(R.id.cvv);
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(WelcomeActivity.this);
       // Uri parse = Uri.parse("file:///android_asset/guide_2.mp4"); 使用这个不能播放
        Uri parse = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.guide_2);
        cvv.setVideoURI(parse);
        cvv.start();
        cvv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
               // cvv.start();
                startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        cvv.destroyDrawingCache();
    }
}
